package com.kingdee.eas.basedata.assistant.client;

import java.awt.event.ActionEvent;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;

import com.kingdee.bos.BOSException;
import com.kingdee.bos.ctrl.swing.event.DataChangeEvent;
import com.kingdee.bos.ctrl.swing.event.DataChangeListener;
import com.kingdee.bos.dao.IObjectPK;
import com.kingdee.bos.dao.ormapping.ObjectUuidPK;
import com.kingdee.bos.metadata.entity.EntityViewInfo;
import com.kingdee.bos.metadata.entity.FilterInfo;
import com.kingdee.bos.metadata.entity.FilterItemInfo;
import com.kingdee.bos.metadata.entity.SelectorItemCollection;
import com.kingdee.bos.metadata.entity.SelectorItemInfo;
import com.kingdee.bos.metadata.query.util.CompareType;
import com.kingdee.eas.basedata.assistant.ProjectCollection;
import com.kingdee.eas.basedata.assistant.ProjectFactory;
import com.kingdee.eas.basedata.assistant.ProjectInfo;
import com.kingdee.eas.basedata.master.account.client.AccountPromptBox;
import com.kingdee.eas.basedata.master.auxacct.AuxAccountUtils;
import com.kingdee.eas.basedata.master.auxacct.GeneralAsstActTypeCollection;
import com.kingdee.eas.basedata.master.auxacct.GeneralAsstActTypeFactory;
import com.kingdee.eas.basedata.master.auxacct.GeneralAsstActTypeGroupCollection;
import com.kingdee.eas.basedata.master.auxacct.GeneralAsstActTypeGroupFactory;
import com.kingdee.eas.basedata.master.auxacct.GeneralAsstActTypeInfo;
import com.kingdee.eas.basedata.master.auxacct.client.GeneralAuxacctPromptBox;
import com.kingdee.eas.basedata.org.CtrlUnitInfo;
import com.kingdee.eas.common.client.SysContext;
import com.kingdee.eas.cp.bc.MakeControl;
import com.kingdee.eas.cp.bc.client.GeneralAsstActTypePromptBox;
import com.kingdee.eas.custom.synchronizationDataFacadeFactory;
import com.kingdee.eas.ma.base.client.BgCostCenterBaseF7;
import com.kingdee.eas.util.client.MsgBox;


public class ProjectEditUICTEx extends ProjectEditUI{

	public ProjectEditUICTEx() throws Exception {
		super();
		// TODO Auto-generated constructor stub
	}
    public void loadFields() {  
        
        
    	kDBizPromptBox1.setData(editData.getAdmin());  
    
        super.loadFields();  
       }  
    @Override
    public void onLoad() throws Exception {
    	super.onLoad();
    	
    	CtrlUnitInfo CU = SysContext.getSysContext().getCurrentCtrlUnit();
		BgCostCenterBaseF7 orgView = new BgCostCenterBaseF7(this);  //拿到成本中心封装好的查询
			 		  
	    orgView.setRootUnitID(CU.getId().toString());
	    
        orgView.setMultiSelect(false);//多选
        orgView.setContainSealUp(true);	
		this.kDBizPromptBox1.setSelector(orgView);
		
//		GeneralAsstActTypeGroupCollection gagc=GeneralAsstActTypeGroupFactory.getRemoteInstance().getGeneralAsstActTypeGroupCollection("where number='SJ07' and cu.id='"+CU.getId().toString()+"'");
//		AuxAccountUtils.assignGeneralBizPromptBox(this.kDBizPromptBox2,gagc.get(0).getId().toString(), true, this);
//		MakeControl.makeAsstActTypeF7(this.kDBizPromptBox2, this);
		EntityViewInfo view=new EntityViewInfo();
		FilterInfo filter=new FilterInfo();
		filter.getFilterItems().add(new FilterItemInfo("group.number","SJ07"));
		view.setFilter(filter);
		kDBizPromptBox2.setEntityViewInfo(view);
		
		//左树右表 直接调用系统方法		
		this.kDBizPromptBox2.addDataChangeListener(new DataChangeListener(){
			@Override
			public void dataChanged(DataChangeEvent e) {
				GeneralAsstActTypeInfo newValue = (GeneralAsstActTypeInfo)e.getNewValue();
				kDBizMultiLangArea1.setSelectedItemData(newValue.getName());
			}			
		});
    }
 
    public SelectorItemCollection getSelectors() {
    	
    	SelectorItemCollection sic = new SelectorItemCollection();
    	/* 579 */     sic.add(new SelectorItemInfo("CU"));
    	/* 580 */     sic.add(new SelectorItemInfo("isSysCreate"));
    	/* 581 */     sic.add(new SelectorItemInfo("name"));
    	/* 582 */     sic.add(new SelectorItemInfo("number"));
    	/* 583 */     sic.add(new SelectorItemInfo("description"));
    	/* 584 */     sic.add(new SelectorItemInfo("type"));
    	/* 585 */     sic.add(new SelectorItemInfo("status"));
    	/* 586 */     sic.add(new SelectorItemInfo("dutyPerson"));
    	/* 587 */     sic.add(new SelectorItemInfo("scheduleStartDate"));
    	/* 588 */     sic.add(new SelectorItemInfo("schedulEndDate"));
    	/* 589 */     sic.add(new SelectorItemInfo("factStartDate"));
    	/* 590 */     sic.add(new SelectorItemInfo("factEndDate"));
    	/* 591 */     sic.add(new SelectorItemInfo("process"));
    	/* 592 */     sic.add(new SelectorItemInfo("attachment"));
    	/* 593 */     sic.add(new SelectorItemInfo("address"));
    	/* 594 */     sic.add(new SelectorItemInfo("address.*"));
    	/* 595 */     sic.add(new SelectorItemInfo("parent"));
    	/* 596 */     sic.add(new SelectorItemInfo("parent.name"));
    	/* 597 */     sic.add(new SelectorItemInfo("parent.number"));
    	/* 598 */     sic.add(new SelectorItemInfo("parent.status"));
    	/* 599 */     sic.add(new SelectorItemInfo("isLeaf"));
    	/* 600 */     sic.add(new SelectorItemInfo("level"));
    	/* 601 */     sic.add(new SelectorItemInfo("longNumber"));
    	/* 602 */     sic.add(new SelectorItemInfo("prjManager.*"));
    	/* 603 */     sic.add(new SelectorItemInfo("company"));
    	/* 604 */     sic.add(new SelectorItemInfo("company.*"));
    	/* 605 */     sic.add(new SelectorItemInfo("isListItem"));
    	/*     */ 
        sic.add(new SelectorItemInfo("admin.*"));  
        sic.add(new SelectorItemInfo("useDepartment.*"));  
        return sic;  
    }  



    	@Override
		protected void verifyInput(ActionEvent e) throws Exception {
			super.verifyInput(e);
			if (null == this.editData.get("admin")) {
				   MsgBox.showWarning("所属部门不能为空");
				   abort();
			}
			if (null == this.editData.get("useDepartment")) {
				   MsgBox.showWarning("使用科室不能为空");
				   abort();
			}
		
			if(this.editData.get("number") != null){
				    String number = this.editData.get("number").toString();
	
			        EntityViewInfo view = new EntityViewInfo();
			        FilterInfo filter = new FilterInfo();       
			        filter.getFilterItems().add(new FilterItemInfo("number", number,CompareType.INCLUDE));
			        view.setFilter(filter);   			    					
				    ProjectCollection data = ProjectFactory.getRemoteInstance().getProjectCollection(view);
				       
				if(data == null || data.size() == 0){
				}else if(this.oprtState.equals("ADDNEW")){
					MsgBox.showWarning("此编码已存在");
					abort();
				}
			}
		}
    	

}
